package org.springmvc.service;

import org.springframework.stereotype.Service;
import org.springmvc.dao.UserDao;
import org.springmvc.entity.User;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author tangjialin on 2016-05-31 0031.
 */
@Service
public class UserService {
	@Resource
	private UserDao userDao;

	public User queryUser (Long id) {
		User user = userDao.queryUser(id);
		return user;
	}

	public User inserOrUpdateUser (User user) {
		if (user == null) return null;
		if (user.getId() == null) {
			user.setCreateTime(new Date());
			userDao.insertUser(user);
		} else {
			userDao.updateUser(user);
		}
		return user;
	}
}
